using System;
using System.Collections.Generic;
using System.Text;
using ECommerce.Library;
using System.IO;
using System.Web;
using ECommerce.Library.ECommerce;

namespace AutoGear.BLL
{
    public sealed class ProductFileAccessUtility : FileAccessUtility
    {
        //private const string _productTemplateFilePath = "~/templates/product-template.txt";
        //private const string _productTemplateCsFilePath = "~/templates/product-template-cs.txt";
        private const string _productImageRootPath = "~/upload/images/product/";
        private const int _listImageWidth = 100; //170;
        private const int _listImageHeight = 100; //170;
        private const int _detailImageWidth = 230; //286;
        private const int _detailImageHeight = 203; //286;
        private const int _maxImageWidth = 500;
        private const int _maxImageHeight = 500;
        private const int _largeThumbImageWidth = 220; //100;
        private const int _largeThumbImageHeight = 166; //100;
        private const int _smallThumbImageWidth = 91; //45;
        private const int _smallThumbImageHeight = 113; //45;

        public const string _brandLogoPath = "~/upload/partner-images/";
        public const string _brandBannerPath = "~/upload/partner-banners/";

        private static string CreateSmallThumbnail(string tempImagePath, string outputFilePath, bool addSufix, System.Drawing.Size originalImageDimension)
        {
            try
            {
                string imagePath = null;

                if (originalImageDimension.Width > _smallThumbImageWidth)
                {
                    if (addSufix)
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, _smallThumbImageWidth, true, "_smallthumb");
                    else
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, _smallThumbImageWidth, false, string.Empty);
                }
                else if ((originalImageDimension.Width > originalImageDimension.Height) && (originalImageDimension.Width > _smallThumbImageWidth))
                {
                    if (addSufix)
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, _smallThumbImageWidth, true, "_smallthumb");
                    else
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, _smallThumbImageWidth, false, string.Empty);
                }
                else if ((originalImageDimension.Height > originalImageDimension.Width) && (originalImageDimension.Height > _smallThumbImageHeight))
                {
                    if (addSufix)
                        imagePath = ImageResizer.CreateThumbnailByHeight(tempImagePath, outputFilePath, _smallThumbImageHeight, true, "_smallthumb");
                    else
                        imagePath = ImageResizer.CreateThumbnailByHeight(tempImagePath, outputFilePath, _smallThumbImageHeight, false, string.Empty);
                }
                else
                {
                    if (addSufix)
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, originalImageDimension.Width, true, "_smallthumb");
                    else
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, originalImageDimension.Width, false, string.Empty);
                }
                return imagePath;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private static string CreateLargeThumbnail(string tempImagePath, string outputFilePath, bool addSufix, System.Drawing.Size originalImageDimension)
        {
            try
            {
                string imagePath = null;

                if ((originalImageDimension.Width > originalImageDimension.Height) && (originalImageDimension.Width > _largeThumbImageWidth))
                {
                    if (addSufix)
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, _largeThumbImageWidth, true, "_largethumb");
                    else
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, _largeThumbImageWidth, false, string.Empty);
                }
                else if ((originalImageDimension.Height > originalImageDimension.Width) && (originalImageDimension.Height > _largeThumbImageHeight))
                {
                    if (addSufix)
                        imagePath = ImageResizer.CreateThumbnailByHeight(tempImagePath, outputFilePath, _largeThumbImageHeight, true, "_largethumb");
                    else
                        imagePath = ImageResizer.CreateThumbnailByHeight(tempImagePath, outputFilePath, _largeThumbImageHeight, false, string.Empty);
                }
                else
                {
                    if (addSufix)
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, originalImageDimension.Width, true, "_largethumb");
                    else
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, originalImageDimension.Width, false, string.Empty);
                }
                return imagePath;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private static string CreateListImage(string tempImagePath, string outputFilePath, bool addSufix, System.Drawing.Size originalImageDimension)
        {
            try
            {
                string imagePath = null;

                if ((originalImageDimension.Width > originalImageDimension.Height) && (originalImageDimension.Width > _listImageWidth))
                {
                    if (addSufix)
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, _listImageWidth, true, "_list");
                    else
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, _listImageWidth, false, string.Empty);
                }
                else if ((originalImageDimension.Height > originalImageDimension.Width) && (originalImageDimension.Height > _listImageHeight))
                {
                    if (addSufix)
                        imagePath = ImageResizer.CreateThumbnailByHeight(tempImagePath, outputFilePath, _listImageHeight, true, "_list");
                    else
                        imagePath = ImageResizer.CreateThumbnailByHeight(tempImagePath, outputFilePath, _listImageHeight, false, string.Empty);
                }
                else
                {
                    if (addSufix)
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, originalImageDimension.Width, true, "_list");
                    else
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, originalImageDimension.Width, false, string.Empty);
                }
                return imagePath;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private static string CreateDetailImage(string tempImagePath, string outputFilePath, bool addSufix, System.Drawing.Size originalImageDimension)
        {
            try
            {
                string imagePath = null;

                if ((originalImageDimension.Width > originalImageDimension.Height) && (originalImageDimension.Width > _detailImageWidth))
                {
                    if (addSufix)
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, _detailImageWidth, true, "_detail");
                    else
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, _detailImageWidth, false, string.Empty);
                }
                else if ((originalImageDimension.Height > originalImageDimension.Width) && (originalImageDimension.Height > _detailImageHeight))
                {
                    if (addSufix)
                        imagePath = ImageResizer.CreateThumbnailByHeight(tempImagePath, outputFilePath, _detailImageHeight, true, "_detail");
                    else
                        imagePath = ImageResizer.CreateThumbnailByHeight(tempImagePath, outputFilePath, _detailImageHeight, false, string.Empty);
                }
                else
                {
                    if (addSufix)
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, originalImageDimension.Width, true, "_detail");
                    else
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, originalImageDimension.Width, false, string.Empty);
                }
                return imagePath;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private static string CreateLargeView(string tempImagePath, string outputFilePath, bool addSufix, System.Drawing.Size originalImageDimension)
        {
            try
            {
                string imagePath = null;

                if ((originalImageDimension.Width > originalImageDimension.Height) && (originalImageDimension.Width > _maxImageWidth))
                {
                    if (addSufix)
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, _maxImageWidth, true, "_max");
                    else
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, _maxImageWidth, false, string.Empty);
                }
                else if ((originalImageDimension.Height > originalImageDimension.Width) && (originalImageDimension.Height > _maxImageHeight))
                {
                    if (addSufix)
                        imagePath = ImageResizer.CreateThumbnailByHeight(tempImagePath, outputFilePath, _maxImageHeight, true, "_max");
                    else
                        imagePath = ImageResizer.CreateThumbnailByHeight(tempImagePath, outputFilePath, _maxImageHeight, false, string.Empty);
                }
                else
                {
                    if (addSufix)
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, originalImageDimension.Width, true, "_max");
                    else
                        imagePath = ImageResizer.CreateThumbnail(tempImagePath, outputFilePath, originalImageDimension.Width, false, string.Empty);
                }
                return imagePath;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static Product CreateProductFiles(Product product, string imageTemporaryFilePath)
        {
            try
            {

                if (product == null)
                    throw new ArgumentNullException("product in ProductFileAccessUtility.CreateProductFiles");
                if (!string.IsNullOrEmpty(imageTemporaryFilePath))
                {
                    product = UploadImages(product, imageTemporaryFilePath);
                    FileAccessUtility.DeleteFile(imageTemporaryFilePath);
                }
                product = CreateProductPageFiles(product);
            }
            catch (Exception ex)
            {
                if (!string.IsNullOrEmpty(imageTemporaryFilePath))
                {
                    FileAccessUtility.DeleteFile(imageTemporaryFilePath);
                }
                throw ex;
            }
            return product;
        }

        private static Product CreateProductPageFiles(Product product)
        {
            string cleanProductName = SiteUtility.CleanProductName(product.ProductName);
            string newProductPath = product.Category.CategoryUrl + cleanProductName + ".aspx";
            newProductPath = newProductPath.ToLower();

            //if (File.Exists(HttpContext.Current.Server.MapPath(newProductPath)))
            //    throw new DuplicateException(AutoGearCommonMessage.DuplicateProductName);
            int fileIndex = 1;
            string tmpNewProductPath = newProductPath;
            while (File.Exists(HttpContext.Current.Server.MapPath(tmpNewProductPath)))
            {
                tmpNewProductPath = newProductPath.Replace(".aspx", "_" + fileIndex + ".aspx");
                fileIndex++;
            }
            newProductPath = tmpNewProductPath;

            //if (File.Exists(HttpContext.Current.Server.MapPath(_productTemplateFilePath)))
            //{
            //    try
            //    {
            //        TextReader reader = new StreamReader(HttpContext.Current.Server.MapPath(_productTemplateFilePath));
            //        string templateContent = reader.ReadToEnd();
            //        reader.Close();

            //        templateContent = templateContent.Replace("<##PageName##>", cleanProductName);
            //        templateContent = templateContent.Replace("<##ProductId##>", product.ProductId.ToString());
            //        templateContent = templateContent.Replace("<##ProductClassName##>", cleanProductName.Replace('-', '_').ToLower());

            //        if (!CreateFile(newProductPath, templateContent))
            //            throw new IOException("Failed to create files for product in ProductFileAccessUtility.CreateProductPageFiles");
            //    }
            //    catch (Exception ex)
            //    {
            //        throw ex;
            //    }
            //}
            //else
            //    throw new IOException("_productTemplateFilePath in ProductFileAccessUtility.CreateProductPageFiles");


            //if (File.Exists(HttpContext.Current.Server.MapPath(_productTemplateCsFilePath)))
            //{
            //    try
            //    {
            //        TextReader reader = new StreamReader(HttpContext.Current.Server.MapPath(_productTemplateCsFilePath));
            //        string templateContent = reader.ReadToEnd();
            //        reader.Close();

            //        templateContent = templateContent.Replace("<##ProductClassName##>", cleanProductName.Replace('-', '_').ToLower());
            //        templateContent = templateContent.Replace("<##ProductId##>", product.ProductId.ToString());
            //        templateContent = templateContent.Replace("<##CategoryId##>", product.Category.CategoryId.ToString());

            //        if (!CreateFile(newProductPath + ".cs", templateContent))
            //            throw new IOException("Failed to create files for product in ProductFileAccessUtility.CreateProductPageFiles");
            //    }
            //    catch (Exception ex)
            //    {
            //        throw ex;
            //    }
            //}
            //else
            //    throw new IOException("_productTemplateCsFilePath in ProductFileAccessUtility.CreateProductPageFiles");

            return new Product(product.ProductId, product.ProductName, product.ProductName2, product.ProductDescription, product.ProductImageUrl,
                product.DisplayOrder, product.VisitCount, product.OldPrice, product.RetailPrice,product.AdditionalPrice,product.AdditionalPriceDesc,product.Recipies,product.AdditionalInfo, product.CreateDate,
                product.ItemNumber, product.IsFeatured, product.IsFreeShipping, product.IsNewArrival, product.IsActive,
                product.IsDeleted, product.IsClearenceItem, newProductPath, product.ProductActualPrice, product.CurrentCost, product.StandardCost,
                false, product.Brand, product.Category, product.Stocks);
        }

        public static String UploadImage(string imagePath, string temporaryImagePath)
        {
            if (string.IsNullOrEmpty(temporaryImagePath))
                throw new ArgumentNullException("tempImagePath in ProductFileAccessUtility.CreateSmallThumbnail()");

            FileInfo tempImageInfo = new FileInfo(HttpContext.Current.Server.MapPath(temporaryImagePath));
            if (!tempImageInfo.Exists)
                throw new IOException("Temporary image file not found");

            string imageName = ImageResizer.RandomizeImageFileName(tempImageInfo.Name);
            string outputFilePath = imagePath + imageName;

            System.Drawing.Size originalImageDimension = ImageResizer.GetImageDimension(temporaryImagePath);
            string outImageFilePath = imagePath = ImageResizer.CreateThumbnail(temporaryImagePath, outputFilePath,219,false, string.Empty);
            return imageName;
        }

        private static Product UploadImages(Product product, string temporaryImagePath)
        {
            if (string.IsNullOrEmpty(temporaryImagePath))
                throw new ArgumentNullException("tempImagePath in ProductFileAccessUtility.CreateSmallThumbnail()");

            FileInfo tempImageInfo = new FileInfo(HttpContext.Current.Server.MapPath(temporaryImagePath));
            if (!tempImageInfo.Exists)
                throw new IOException("Temporary image file not found");

            string imageName = ImageResizer.RandomizeImageFileName(tempImageInfo.Name);

            string outputFilePath = _productImageRootPath + imageName;

            System.Drawing.Size originalImageDimension = ImageResizer.GetImageDimension(temporaryImagePath);
            //if (originalImageDimension.Width > 240)
            //{
            //    originalImageDimension.Width = 240;
            //}
            //if (originalImageDimension.Height > originalImageDimension.Width) 
            //{
            //    originalImageDimension.Height = originalImageDimension.Width;
            //}
            ImageResizer.CreateThumbnail(temporaryImagePath, outputFilePath, originalImageDimension.Width, true, "_original");

            string smallThumbFilePath = CreateSmallThumbnail(temporaryImagePath, outputFilePath, true, originalImageDimension);
            string largeThumbFilePath = CreateLargeThumbnail(temporaryImagePath, outputFilePath, true, originalImageDimension);
            string listImageFilePath = CreateListImage(temporaryImagePath, outputFilePath, true, originalImageDimension);
            string detailImageFilePath = CreateDetailImage(temporaryImagePath, outputFilePath, true, originalImageDimension);
            string largeImageFilePath = CreateLargeView(temporaryImagePath, outputFilePath, true, originalImageDimension);

            product.ProductImageUrl = listImageFilePath;

            return new Product(product.ProductId, product.ProductName, product.ProductName2, product.ProductDescription, listImageFilePath,
                product.DisplayOrder, product.VisitCount, product.OldPrice, product.RetailPrice,product.AdditionalPrice,product.AdditionalPriceDesc, product.Recipies,product.AdditionalInfo, product.CreateDate,
                product.ItemNumber, product.IsFeatured, product.IsFreeShipping, product.IsNewArrival, product.IsActive,
                product.IsDeleted, product.IsClearenceItem, product.ProductUrl, product.ProductActualPrice, product.CurrentCost, product.StandardCost,
                false, product.Brand, product.Category, product.Stocks);
        }

        public static Product ChangeImages(Product product, string temporaryImagePath)
        {
            if (string.IsNullOrEmpty(temporaryImagePath))
                throw new ArgumentNullException("tempImagePath in ProductFileAccessUtility.CreateSmallThumbnail()");

            FileInfo tempImageInfo = new FileInfo(HttpContext.Current.Server.MapPath(temporaryImagePath));
            if (!tempImageInfo.Exists)
                throw new IOException("Temporary image file not found");

            string imageName = ImageResizer.RandomizeImageFileName(tempImageInfo.Name);

            string outputFilePath = _productImageRootPath + imageName;

            System.Drawing.Size originalImageDimension = ImageResizer.GetImageDimension(temporaryImagePath);
            if (originalImageDimension.Width > 240)
            {
                originalImageDimension.Width = 240;
            }
            if (originalImageDimension.Height > originalImageDimension.Width)
            {
                originalImageDimension.Height = originalImageDimension.Width;
            }
            ImageResizer.CreateThumbnail(temporaryImagePath, outputFilePath, originalImageDimension.Width, true, "_original");

            string smallThumbFilePath = CreateSmallThumbnail(temporaryImagePath, outputFilePath, true, originalImageDimension);
            string largeThumbFilePath = CreateLargeThumbnail(temporaryImagePath, outputFilePath, true, originalImageDimension);
            string listImageFilePath = CreateListImage(temporaryImagePath, outputFilePath, true, originalImageDimension);
            string detailImageFilePath = CreateDetailImage(temporaryImagePath, outputFilePath, true, originalImageDimension);
            string largeImageFilePath = CreateLargeView(temporaryImagePath, outputFilePath, true, originalImageDimension);

            product.ProductImageUrl = listImageFilePath;

            return product;
        }

        private static void DeleteProductPages(Product product)
        {
            if (product == null)
                throw new ArgumentNullException("product in ProductFileAccessUtility.DeleteProductPages");
            if (string.IsNullOrEmpty(product.ProductName))
                throw new ArgumentNullException("product.ProductName in ProductFileAccessUtility.DeleteProductPages");
            //if (string.IsNullOrEmpty(_productTemplateFilePath))
            //    throw new ArgumentNullException("_productTemplateFilePath in ProductFileAccessUtility.DeleteProductPages");
            if (string.IsNullOrEmpty(product.Category.CategoryUrl))
                throw new ArgumentNullException("product.Category.CategoryUrl in ProductFileAccessUtility.DeleteProductPages");

            //string cleanProductName = SiteUtility.CleanProductName(product.ProductName);
            //string oldProductPath = product.Category.CategoryUrl + cleanProductName + ".aspx";
            //oldProductPath = oldProductPath.ToLower();

            string oldProductPath = product.ProductUrl; 

            string pathToDelete = HttpContext.Current.Server.MapPath(oldProductPath).ToLower();
            string siteRootPath = HttpContext.Current.Server.MapPath("~").ToLower();

            if (pathToDelete.StartsWith(siteRootPath) && pathToDelete.Length <= siteRootPath.Length + 1)
                throw new InvalidOperationException("Delete Path is not valid in ProductFileAccessUtility.DeleteProductPages");

            if (File.Exists(HttpContext.Current.Server.MapPath(oldProductPath)))
            {
                try
                {
                    DeleteFile(oldProductPath);
                }
                catch (Exception ex)
                {
                    throw new IOException("Failed to delete aspx file in ProductFileAccessUtility.DeleteProductPages");
                }
            }

            if (File.Exists(HttpContext.Current.Server.MapPath(oldProductPath + ".cs")))
            {
                try
                {
                    DeleteFile(oldProductPath + ".cs");
                }
                catch (Exception ex)
                {
                    throw new IOException("Failed to delete cs file in ProductFileAccessUtility.DeleteProductPages");
                }
            }
        }

        public static void DeleteProductFiles(Product product)
        {
            DeleteProductPages(product);
        }

        public static Product UpdateProductFiles(Product oldProduct, Product product)
        {
            DeleteProductFiles(oldProduct);

            string cleanProductName = SiteUtility.CleanProductName(product.ProductName);
            string newProductPath = product.Category.CategoryUrl + cleanProductName + ".aspx";
            newProductPath = newProductPath.ToLower();

            //if (File.Exists(HttpContext.Current.Server.MapPath(newProductPath)))
            //    throw new DuplicateException(AutoGearCommonMessage.DuplicateProductName);
            int fileIndex = 1;
            string tmpNewProductPath = newProductPath;
            while (File.Exists(HttpContext.Current.Server.MapPath(tmpNewProductPath)))
            {
                tmpNewProductPath = newProductPath.Replace(".aspx", "_" + fileIndex + ".aspx");
                fileIndex++;
            }
            newProductPath = tmpNewProductPath;

            //if (File.Exists(HttpContext.Current.Server.MapPath(_productTemplateFilePath)))
            //{
            //    try
            //    {
            //        TextReader reader = new StreamReader(HttpContext.Current.Server.MapPath(_productTemplateFilePath));
            //        string templateContent = reader.ReadToEnd();
            //        reader.Close();

            //        templateContent = templateContent.Replace("<##PageName##>", cleanProductName);
            //        templateContent = templateContent.Replace("<##ProductId##>", product.ProductId.ToString());
            //        templateContent = templateContent.Replace("<##ProductClassName##>", cleanProductName.Replace('-', '_').ToLower());

            //        if (!CreateFile(newProductPath, templateContent))
            //            throw new IOException("Failed to create files for product in ProductFileAccessUtility.CreateProductPageFiles");
            //    }
            //    catch (Exception ex)
            //    {
            //        throw ex;
            //    }
            //}
            //else
            //    throw new IOException("_productTemplateFilePath in ProductFileAccessUtility.CreateProductPageFiles");


            //if (File.Exists(HttpContext.Current.Server.MapPath(_productTemplateCsFilePath)))
            //{
            //    try
            //    {
            //        TextReader reader = new StreamReader(HttpContext.Current.Server.MapPath(_productTemplateCsFilePath));
            //        string templateContent = reader.ReadToEnd();
            //        reader.Close();

            //        templateContent = templateContent.Replace("<##ProductClassName##>", cleanProductName.Replace('-', '_').ToLower());
            //        templateContent = templateContent.Replace("<##ProductId##>", product.ProductId.ToString());
            //        templateContent = templateContent.Replace("<##CategoryId##>", product.Category.CategoryId.ToString());

            //        if (!CreateFile(newProductPath + ".cs", templateContent))
            //            throw new IOException("Failed to create files for product in ProductFileAccessUtility.CreateProductPageFiles");
            //    }
            //    catch (Exception ex)
            //    {
            //        throw ex;
            //    }
            //}
            //else
            //    throw new IOException("_productTemplateCsFilePath in ProductFileAccessUtility.CreateProductPageFiles");

            return new Product(product.ProductId, product.ProductName, product.ProductName2, product.ProductDescription, product.ProductImageUrl,
                product.DisplayOrder, product.VisitCount, product.OldPrice, product.RetailPrice,product.AdditionalPrice,product.AdditionalPriceDesc, product.Recipies,product.AdditionalInfo, product.CreateDate,
                product.ItemNumber, product.IsFeatured, product.IsFreeShipping, product.IsNewArrival, product.IsActive,
                product.IsDeleted, product.IsClearenceItem, newProductPath, product.ProductActualPrice, product.CurrentCost, product.StandardCost,
                false, product.Brand, product.Category, product.Stocks);
        }

        public static bool DeleteProductImage(Product product)
        {
            FileAccessUtility.DeleteFile(product.ProductImageUrl);
            FileAccessUtility.DeleteFile(product.ProductImageUrl.Replace("list", "max"));
            FileAccessUtility.DeleteFile(product.ProductImageUrl.Replace("list", "smallthumb"));
            FileAccessUtility.DeleteFile(product.ProductImageUrl.Replace("list", "largethumb"));
            FileAccessUtility.DeleteFile(product.ProductImageUrl.Replace("list", "detail"));
            FileAccessUtility.DeleteFile(product.ProductImageUrl.Replace("list", "original"));
            return true;
        }

        public static string UploadAdditionalImages(string temporaryImagePath)
        {
            if (string.IsNullOrEmpty(temporaryImagePath))
                throw new ArgumentNullException("tempImagePath in ProductFileAccessUtility.CreateSmallThumbnail()");

            FileInfo tempImageInfo = new FileInfo(HttpContext.Current.Server.MapPath(temporaryImagePath));
            if (!tempImageInfo.Exists)
                throw new IOException("Temporary image file not found");

            string imageName = ImageResizer.RandomizeImageFileName(tempImageInfo.Name);

            string outputFilePath = _productImageRootPath + imageName;

            System.Drawing.Size originalImageDimension = ImageResizer.GetImageDimension(temporaryImagePath);

            ImageResizer.CreateThumbnail(temporaryImagePath, outputFilePath, originalImageDimension.Width, true, "_original");

            string smallThumbFilePath = CreateSmallThumbnail(temporaryImagePath, outputFilePath, true, originalImageDimension);
            string largeThumbFilePath = CreateLargeThumbnail(temporaryImagePath, outputFilePath, true, originalImageDimension);
            string listImageFilePath = CreateListImage(temporaryImagePath, outputFilePath, true, originalImageDimension);
            string detailImageFilePath = CreateDetailImage(temporaryImagePath, outputFilePath, true, originalImageDimension);
            string largeImageFilePath = CreateLargeView(temporaryImagePath, outputFilePath, true, originalImageDimension);

            return listImageFilePath;
        }
    }
}
